clear global;clc;

% 输入三个点的坐标
x(1) = -1; y(1) = 0;
x(2) = 2; y(2) = 0;
x(3) = 0; y(3) = 2;
% 定义的各种系数
a(1) = x(2) * y(3) - y(2) * x(3);
a(2) = x(3) * y(1) - y(3) * x(1);
a(3) = x(1) * y(2) - y(1) * x(2);

b(1) = y(2) - y(3);
b(2) = y(3) - y(1);
b(3) = y(1) - y(2);

c(1) = x(3) - x(2);
c(2) = x(1) - x(3);
c(3) = x(2) - x(1);

% 坐标变换为 [x,y]=A.[xi,eta]+B
% 矩阵 A
delta_e = 1/2 * (b(1) * c(2) - b(2) * c(1));
mat = [
    c(2), -c(1);
    -b(2), b(1)];
% 列向量B
vec = [x(3); y(3)];

% 采样点和权重
Triangle_Gauss_7;
pNum=size(pos);

%  累加求和
sum=0;
for ni=1:pNum(1)
    sum = sum+ coe(ni)*testFn(ToXY(pos(ni,:),mat,vec));
end

% 参考文献中，高斯积分法的雅可比因子为 delta_e，而非  det[J]=2delta_e;
(delta_e)*sum


% 测试函数, x-y 空间下
function F=testFn(xy)
x=xy(1);y=xy(2);
F=x^3+y^3+6*x^2*y+6*x*y^2;
end

% 坐标变换, 由 xi, eta  给出对应的 x, y
function xy=ToXY(xi_eta,mat,vec)
xy=(mat*xi_eta'+vec)';
end